<template>
    <bi-form ref="form"  label-width="100px">
        <div class="alert alert-warning" style="font-size: 12px; padding: 10px;" v-if="first">
            第一次登录，请修改新密码！
        </div>
        <bi-form-item label="原密码" >
            <bi-input type="password" v-model="old_password" placeholder="请输入原密码" required />
        </bi-form-item>
        <bi-form-item label="新密码" >
            <bi-input type="password" v-model="new_password" placeholder="请输入新密码" required /> 
        </bi-form-item>
        <bi-form-item label="确认密码" >
            <bi-input type="password" v-model="confirm_password" placeholder="请再次输入新密码" required />
        </bi-form-item>
    </bi-form>
</template>


<script>
export default {
    dialog:{
        title:'修改我的密码',
        width:400,
    },
    data(){

        return {
            old_password:'',
            new_password:'',
            confirm_password:''
        }
    },
    props:{
        first:{
            type:Boolean,
            default:false
        }
    },
    methods:{
        dialogOk(){
            if(this.$refs.form.check()){
                if (this.new_password != this.confirm_password){
                    this.$alert({text:'两次密码不一致',type:'warning'});
                    return false;
                }

                this.$ajax({
                    url:this.$url({app:'admin',controller:'my',action:'modifyPassword'}),
                    data:{
                        new_password:this.new_password,
                        old_password:this.old_password
                    },
                    success:()=>{

                        if (this.first){
                            this.$alert({
                                text:'修改成功，请重新登录！',
                                type:'success',
                            },()=>{this.$go({app:'admin',controller:'user',action:'logout'})});
                        }else{
                            this.$alert({text:'修改成功',type:'success'});
                            this.dialog.close();
                        }
                    }
                });
            }

            
            return false;
            
        }

       
    }
}</script>